﻿using Me.Amon.POS.C;
namespace Me.Amon.POS.M
{
    public class MSoDetail : MPos
    {
        public string so_id;

        public string spu_id;
        public MSpu spu;

        public int spu_qty;
        /// <summary>
        /// 零售价
        /// </summary>
        public int spu_price;
        /// <summary>
        /// 会员价
        /// </summary>
        public int vip_price;
        /// <summary>
        /// 折扣价
        /// </summary>
        public int pro_price;
        /// <summary>
        /// 折扣类型
        /// </summary>
        public string pro_name;

        public string guider;
        /// <summary>
        /// 小计
        /// </summary>
        public int subtotal;

        public void GenPrice(MVip vip)
        {
            if (spu == null || spu.price == null)
            {
                return;
            }
            var price = spu.price;

            spu_price = price.price;
            vip_price = price.vip_price;

            pro_price = price.price;
            bool isVip = vip.level > 0 && spu.is_vip;
            if (isVip)
            {
                if (price.vip_type == CSpuPrice.PRICE_TYPE_FIXED)
                {
                    pro_price = price.vip_price;
                }
                else if (price.vip_type == CSpuPrice.PRICE_TYPE_RATIO)
                {
                    pro_price = pro_price * price.vip_price;
                    // 防止3为小数，有1就进。
                    if (pro_price % 100 > 0)
                    {
                        pro_price += 100;
                    }
                    pro_price /= 100;
                }
                pro_name = "会员折扣";
            }
            if (isVip && spu.is_pro || !isVip)
            {
                if (price.pro_type == CSpuPrice.PRICE_TYPE_FIXED)
                {
                    pro_price = price.pro_price;
                }
                else if (price.pro_type == CSpuPrice.PRICE_TYPE_RATIO)
                {
                    pro_price = pro_price * price.pro_price;
                    if (pro_price % 100 > 0)
                    {
                        pro_price += 100;
                    }
                    pro_price /= 100;
                }
                pro_name = price.pro_name;
            }

            subtotal = spu_qty * pro_price;
        }
    }
}
